home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8206 / 8206.xpi / content / webmail / hotmail.js < prev    next >
Encoding:
JavaScript  |  2010-02-02  |  5.2 KB  |  189 lines

  1. window.addEventListener("load",function(event){hotmailsig.pageload(event)},false);
  2. window.addEventListener("unload",function(event){hotmailsig.uninitSig(event)},false);
  3.  
  4. var hotmailsig =
  5. {
  6.     current: null,
  7.     COMPOSE: "EditMessageLight",
  8.     loading: false,
  9.     doc: null,
  10.     pageload: function (event)
  11.     {
  12.         //    WISELOG("[hotmail.js::pageload] >>>>>");
  13.         try
  14.         {
  15.             if (!this.loading)
  16.             {
  17.                 var doc = event.originalTarget;
  18.                 if (doc instanceof Components.interfaces.nsIDOMDocument)
  19.                 {
  20.                     //          WISELOG("[hotmail.js::pageload] defaultView frame?: "+doc.defaultView.frameElement);
  21.                     if (doc.defaultView.frameElement)
  22.                     {
  23.                         var fclass = doc.defaultView.frameElement.getAttribute("class");
  24.                         //            WISELOG("[hotmail.js::pageload] frame class: "+fclass);
  25.                         // Frame within a tab was loaded. doc should be the root document of
  26.                         // the frameset.
  27.                         // Find the root document:
  28.                         while (doc.defaultView.frameElement)
  29.                         {
  30.                             doc = doc.defaultView.frameElement.ownerDocument;
  31.                         }
  32.                     }
  33.  
  34.                     this.doc = doc;
  35.                 }
  36.  
  37.                 if (this.doc)
  38.                 {
  39.                     //          WISELOG("[hotmail.js::pageload] this.doc");
  40.                     this.loading = true;
  41.                     wisestampsig.refreshCallback = hotmailsig.refreshSignature;
  42.                     setTimeout(function ()
  43.                     {
  44.                         hotmailsig.init();
  45.                     },
  46.                     1000);
  47.                 }
  48.             }
  49.         } catch(e)
  50.         {
  51.             //      WISELOG(e);
  52.         }
  53.     },
  54.     uninitSig: function ()
  55.     {
  56.         var viewDiv = document.getElementById("ws_view");
  57.         if (viewDiv) viewDiv.removeEventListener("DOMNodeInserted", hotmailsig.composeInserted, false);
  58.         var compose = document.getElementById("composeMessage");
  59.         if (compose)
  60.         {
  61.             try
  62.             {
  63.                 this._composeListener = false;
  64.                 compose.removeEventListener("DOMAttrModified", hotmailsig.composeModified, false);
  65.             } catch(e)
  66.             {
  67.  
  68.             }
  69.         }
  70.         this.uninitView();
  71.     },
  72.     uninitView: function ()
  73.     {
  74.         if (this.current && this["uninit" + this.current])
  75.         {
  76.             this["uninit" + this.current]();
  77.         }
  78.     },
  79.     init: function ()
  80.     {
  81.         //    WISELOG("[hotmail.js::init] SetupCompose");
  82.         var reg = /.+mail\.live\..+\/mail\/(.+)\.aspx.+/;
  83.         //    WISELOG("[hotmail.js::init] location = " + location.toString());
  84.         var result = location.toString().match(reg);
  85.         //    WISELOG("[hotmail.js::init] result = "+result);
  86.         if (result && result[1])
  87.         {
  88.             var mode = result[1];
  89.             //      WISELOG("[hotmail.js::init] MODE: "+mode);
  90.             switch (mode)
  91.             {
  92.             case this.COMPOSE:
  93.                 this.setupCompose();
  94.                 break;
  95.             default:
  96.                 break;
  97.             }
  98.         }
  99.     },
  100.     get mode()
  101.     {
  102.         var search = location.search;
  103.         var reg = /Action=([^&]+)/;
  104.         var m = search.match(reg);
  105.         if (m && m[1])
  106.         {
  107.             return m[1];
  108.         } else
  109.         {
  110.             return null;
  111.         }
  112.     },
  113.     iframeTries: 0,
  114.     setupCompose: function (aSkipCheck)
  115.     {
  116.         //    WISELOG("[hotmail.js::setupCompose] >>>>>");
  117.         if (!aSkipCheck && document.getElementById("wisestamp_toolbarbutton"))
  118.         {
  119.             //      WISELOG("[hotmail.js::setupCompose] Already loaded");
  120.             return;
  121.         }
  122.         //var toolbars = evaluateXPath(document,
  123.         //  "//div[@id='mainToolbar']//ul[@class='Toolbar']");
  124.         var toolbars = evaluateXPath(document,
  125.         //"//div[@class='MSN_EDITCONTAINER']//div[@class='MSN_TOOLBAR']");
  126.         "//div[@class='ButtonList Enabled']");
  127.         //    WISELOG("[hotmail.js::setupCompose] toolbars = "+toolbars);
  128.         if (toolbars.length > 0)
  129.         {
  130.             var toolbar = toolbars[0];
  131.             this.addWisestampIcon(toolbar);
  132.  
  133.             var iframes = evaluateXPath(document, "//iframe[@class='RichText']");
  134.             if (this.mode == "ResumeDraft") this.iframe = iframes[0];
  135.             else
  136.             {
  137.                 for (var i = 0; iframes && i < iframes.length; i++)
  138.                 this.insertSignature(iframes[i], false);
  139.             }
  140.         }
  141.     },
  142.     addWisestampIcon: function (toolbar)
  143.     {
  144.         //    WISELOG("[hotmail.js::addWisestampIcon] >>>>>");
  145.         if (!wisestampsig.showButton) return;
  146.         var end = toolbar.childNodes[toolbar.childNodes.length - 1];
  147.         var li = hotmailsig.doc.createElement("span");
  148.         li.setAttribute("id", "wisestamp_toolbarbutton");
  149.         li.setAttribute("class", "MSN_TOOLBAR_GROUP");
  150.         li.setAttribute("style", "display: inline; white-space: nowrap;");
  151.         var span = hotmailsig.doc.createElement("span");
  152.         span.setAttribute("tabindex", "0");
  153.         var width = "24";
  154.         if (wisestampsig.isFoxytunesInstalled) width = "55"
  155.         span.setAttribute("style", "float: right; position: relative; display: inline; width: " + width + "px; height: 30px; vertical-align: middle;")
  156.         var img = hotmailsig.doc.createElement("img");
  157.         img.setAttribute("src", wisestampsig.icon);
  158.         img.setAttribute("alt", "Wisestamp");
  159.         img.setAttribute("style", "width: 16px; height: 16px; vertical-align: bottom; position: absolute; margin-left: 5px; margin-top: 14px;");
  160.         span.appendChild(img);
  161.         li.appendChild(span);
  162.         var spacer = document.createElement("table");
  163.         spacer.setAttribute("style", "width: 35px; height: 20px; position: absolute;");
  164.         //li.appendChild(spacer);
  165.         toolbar.insertBefore(li, end);
  166.         //toolbar.appendChild(li);
  167.         wisestampsig.initOptionsIcon(li);
  168.     },
  169.     uninitCompose: function ()
  170.     {
  171.  
  172.     },
  173.     iframeTries: 1,
  174.     refreshSignature: function ()
  175.     {
  176.         wisestampsig.insertSignature(hotmailsig.iframe, false);
  177.     },
  178.     insertSignature: function (iframe)
  179.     {
  180.         //    WISELOG("[hotmail.js::insertSignature] >>>>>");
  181.         this.iframe = iframe;
  182.         this.iframeLoad(false);
  183.     },
  184.     iframeLoad: function (event)
  185.     {
  186.         //    WISELOG("[hotmail.js::iframeLoad] >>>>>");
  187.         wisestampsig.insertSignature(hotmailsig.iframe, true);
  188.     }
  189. };